package com.m2bshop.shop.service.impl;

import com.m2bshop.shop.dao.JMFgoodsDao;
import com.m2bshop.shop.dao.JmfOrderDao;
import com.m2bshop.shop.dao.PayorderDao;
import com.m2bshop.shop.pojo.JMFgoods;
import com.m2bshop.shop.pojo.JmfOrder;
import com.m2bshop.shop.service.JmfOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class JmfOrderServiceImpl implements JmfOrderService {
    @Autowired
    private JmfOrderDao jmfOrderDao;

    @Autowired
    private JMFgoodsDao jmFgoodsDao;

    @Autowired
    private PayorderDao payorderDao;


    @Override
    public List<JmfOrder> findAwaitingPayOrder(){
        return jmfOrderDao.findAwaitingPayOrder();
    }

    @Override
    public List<JmfOrder> findAwaitingShipOrder(){
        return jmfOrderDao.findAwaitingShipmentOrder();
    }

    @Override
    public List<JmfOrder> findshipedOrder(){
        return jmfOrderDao.findShipedmentOrder();
    }

    @Override
    public List<JmfOrder> findCompletedOrder(){
        return jmfOrderDao.findCompletedOrder();
    }

    @Override
    public List<JmfOrder> findCancelledOrder(){
        return jmfOrderDao.findCancelledOrder();
    }

    @Override
    public List<JmfOrder> findJmfOrderByTitle(String jtitle) {
        return jmfOrderDao.findJmfOrderByTitle(jtitle);
    }

    @Override
    public void createorder(int sid) {
        JMFgoods jmFgoods = jmFgoodsDao.selectById(sid);
        JmfOrder jmfOrder = new JmfOrder();
        jmfOrder.setJtitle(jmFgoods.getName());
        jmfOrder.setJprice(jmFgoods.getPrice());
        jmfOrder.setJweight(jmFgoods.getWeight());
        jmfOrder.setJdate(new Date());
        jmfOrder.setJtotal(jmFgoods.getWeight()*jmFgoods.getPrice());
        jmfOrder.setSid(sid);
        jmfOrder.setStatus("待支付");
        payorderDao.insert(jmfOrder);
    }


}
